Skip to content

Merge conflicts mechanically first and never commit an unchecked merge - #987

Merged
coderhelm[bot] merged 2 commits into
mainfrom
fix/merge-keeps-both-sides
Dec 5, 2026
Merged

coderhelm[bot] merged 2 commits into
mainfrom
fix/merge-keeps-both-sides

Conversation

@nambok

@nambok nambok commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

When merging the base into a branch hit a conflict, CoderHelm sent the whole of every file both sides had changed to the model. The files were cut at a size limit. It then committed the reply after three weak checks: the reply was not empty, it kept at least 30% of the smaller side, and a bracket scan was no worse than the branch's. A reply that opened with prose and then gave a rewritten file passed all three. It dropped most of the base's changes and was pushed without compiling. For a dashboard component, the right result was the base's file with the branch's two added lines.

Now no merge result is committed if it adds prose, drops either side's changes, or fails to parse.

Changes

  • New passes::merge3: a line-based three-way merge (patience anchors plus exact matching). Changes that only one side made, or that both sides made the same way, apply mechanically, with no model. Lines both sides agree on are trimmed from the edges of a conflicting hunk.
  • The model is asked only about a hunk both sides changed differently. It sees that hunk's ancestor, ours and theirs, plus a few unchanged lines around it, never the whole file. Its reply is read from <resolved> tags, and anything around them is dropped. Prose, markdown fences and conflict markers inside the reply are refused. So is a reply longer than both sides together, or one that loses an identifier either side added.
  • merge3::check_merged runs on every merged file before commit:
    • no new conflict markers, prose or fences
    • a line count within the base plus both sides' changes
    • every identifier either side added is still there
    • the file parses as well as the sides do: tree-sitter for TS, TSX, JS, Python and Rust; JSON, YAML and TOML must parse; other code gets the bracket scan
  • A failed merge is retried with smaller hunks (cut where the two sides agree, with no context). If it fails again, pr::resolve_conflicts pushes nothing and leaves the branch as it was. It records the failure as an OwnProblem (Tooling: an internal alert, plus a run page line when the run is known) and returns merge3::Refused with the reason. await_merge and branch_update read a refusal as the conflict still standing. Before this change, a failed check returned Ok(false), which some callers read as "nothing conflicted".
  • pr::merge_file (also used by restack) now goes through the same path. The whole-file merge prompt is gone.
  • Incident case xy_merge_keeps_both_sides_and_parses (.rs and .md) replays the failure with invented content.

Verification

  • cargo fmt --all --check, rustfmt --check --edition 2021 worker/src/passes/incidents/*.rs
  • cargo clippy -p common -p worker -p gateway --all-targets -- -D warnings
  • cargo test -p common -p worker -p gateway: all pass. The new tests cover:
    • A TSX file where the base changed many lines and the branch added two merges mechanically. The model stub, which returns prose plus a rewritten file, is never asked.
    • The result that was pushed fails the checks for prose, size and parse.
    • For a real overlapping hunk, the model sees only that hunk. A prose-and-rewrite reply is refused on both tries and nothing is pushed, while a correct hunk reply lands in place.
  • brand_spelling.py, domain_examples.py

A conflicted merge of the base handed every file both sides changed to
the model whole, cut at a size limit, and committed the reply after weak
checks. A reply of prose followed by a rewritten file passed them.

Each file is now merged three ways: changes only one side made apply
mechanically, the model sees only a hunk both sides changed differently,
and its reply must be that hunk's code. The merged file is checked
before commit (no prose or markers, size within both sides' changes,
both sides' added identifiers kept, it parses). A failed merge retries
with smaller hunks, then pushes nothing and is recorded as CoderHelm's
own problem.

Incident case xy pins the invariant.
@nambok nambok added the ch-review CoderHelm reviews this pull request label Dec 5, 2026
coderhelm[bot]

This comment was marked as outdated.

@coderhelm

coderhelm Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Post-merge health check FAILED: the merge of ca4ce10 has NEW failing checks that were not failing before the merge:

  • Pin the dashboard's newest green commit (failure, started 2026-12-06T01:17:55Z)
    Failures that were already there before the merge were ignored. Rolling a deploy back needs the approval of whoever owns it: should ca4ce10 be rolled back?
    Auto-merge
    The rest is in the pull request description.

@coderhelm coderhelm Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved with notes fe3045f (merged)

@coderhelm
coderhelm Bot merged commit ca4ce10 into main Dec 5, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ch-review CoderHelm reviews this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant